#pragma once

#include "IBrushMonster.h"
#include "Common/Timer/TimerAxis.h"

class BrushUnion : public IBrushMonster, public ITimerHandler
{
	enum
	{
		ETimer_ID_BrushBoss = 1,
		ETimer_ID_NextWave = 2,
		BROAD_NEXT_WAVE_EX_SEC = 2,//广播下一波延迟时间（主要是为了解决前后端一起倒计时会有误差的问题）
	};
	struct SWaveMons 
	{
		SET_UINT64 setMons;
		SET_UINT64 setBoss;
		SWaveMons()
		{
			clear();
		}
		void clear()
		{
			setMons.clear();
			setBoss.clear();
		}
		bool IsAllDie()
		{
			return (setBoss.size() <= 0 && setMons.size() <= 0);
		}
		bool IsAllMonsDie()
		{
			return (setMons.size() <= 0);
		}
	};
public:
	BrushUnion();
	virtual ~BrushUnion();
	///////////////////////////////  IBrushMonster  ///////////////////////////////////////////
	virtual int8_t GetBrushType() { return (int8_t)EDuplicateBrushType::EDuplicateBrushType_Union; };
	virtual bool Init(IDuplicate *pDuplicate);
	virtual void UnInit();
	//获取当前层数
	virtual int32_t CurLayer();
	//获取总层数
	virtual int32_t TotalLayer();
	//获取总波数
	virtual void StartBrush();
	virtual void StopBrush();
	//是否刷怪完成
	virtual bool FinishBrush();
	
	virtual void BrushUpdate();
	virtual void OnMonterDead(uint64_t monsCid, uint32_t monsId, uint32_t count, int32_t formationId,uint64_t killerCid);
	//获取boss状态
	virtual void GetBossState(MAP_UINT32_INT8 &mapState);
	//获取当前波怪物信息
	virtual void GetCurWaveInfo(int32_t &curWave, int32_t &monsDie, int32_t &totalMons, SET_UINT32 &setBoss);
	//是否是有效怪
	virtual bool ValidMons(uint64_t monsCid, int8_t &byBoss);
	/////////////////////////////// ITimerHandler ///////////////////////////////////////////
	virtual void OnTimer(uint32_t nTimerID);
private:
	//刷怪
	void BrushMonster();
	//刷boss怪
	void BrushBossMonster();
	//获取一个最小区域计数的区域
	uint32_t GetMinNumArea(MAP_UINT32_UINT32 &mapAreaNum, SET_UINT32 &setArea);
	//更新区域数量
	void UpdateAreaNum(MAP_UINT32_UINT32 &mapAreaNum,uint32_t areaId,uint32_t num);
	//更新怪物死亡数量
	void UpdateMonsDie(uint64_t monsCid,uint32_t monsId,uint32_t num);
	//通知boss状态
	void NotifyBossState(uint32_t bossId, int8_t state);
	//通知boss出现
	void NotifyBossAppear(uint32_t bossId);
	//通知怪物波数
	void NotifyMonsWave(int32_t waveCd);
	//获取怪物死亡数量
	uint32_t GetMonsDieNum(uint32_t monsId);
	//获取所有已经死亡怪物数量
	int32_t GetMonsTotalDieNum();
	//清空怪物死亡数量
	void ClearMonsDie();
	//当前波是否全部死亡S
	bool IsAllDie();
	//当前波的小怪是否全部死亡
	bool IsAllMonsDie();
	//当前波小怪死亡数量和小怪总数量
	void GetCurMonsNum(int32_t &dieNum, int32_t &totalNum);
	//获取制定波怪物总数量和boss id列表
	void GetWaveMonsNum(int32_t idx,int32_t &totalNum, SET_UINT32 &setBoss);
	//当前波BOSS id列表
	void GetCurBoss(SET_UINT32 &setBoss);
	//通知波数信息
	void NotifyWaveInfo();
	void CheckMonsEnterArea();
private:
	IDuplicate *m_pDuplicate;
	UnionBrushDataCfg *m_pBrush;
	bool m_bBrushFinish;
	bool m_bStart;
	bool m_bWaitBrush;
	int32_t m_maxSize;
	int32_t m_brushCurIdx;
	MAP_UINT32_UINT32 m_mapMonsterDie;
	SWaveMons m_stWaveMons;
	MAP_UINT32_INT8 m_mapBossState; //boss数量
	int32_t m_unionAverageLev; //工会精英平均等级
	SET_UINT64 m_setEnterAreaFight;
	SET_UINT32 m_setAllMons;	//所有的小怪
};